﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using SmartEP.Presenter;
using SmartEP.DTO;

namespace SmartDesktop
{
    public partial class ConnectDatabaseForm : Form,IDatabase
    {
        private DatabasePresenter _presenter;
        public ConnectDatabaseForm()
        {
            InitializeComponent();
            _presenter = new DatabasePresenter(this);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (SmartEP.Model.DBConnection.IsConnectDatabase(Convert.ToString(txtServerName.Text), Convert.ToString(txtDatabaseName.Text), Convert.ToString(txtUserName.Text), Convert.ToString(txtPassword.Text)))
            {
                _presenter.WriteDatabaseXML("Database.xml");
                this.Close();
            }
            else
                MessageBox.Show("Connected to database fail... Please try agian!");
        }

        private void frmConnectDatabase_Load(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
                Application.Exit();
        }
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Enter))
            {
                //
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        #region Property
        public string ServerName
        {
            get
            {
                return txtServerName.Text;
            }
            set
            {
                txtServerName.Text = value;
            }
        }

        public string DatabaseName
        {
            get
            {
                return txtDatabaseName.Text;
            }
            set
            {
                txtDatabaseName.Text = value;
            }
        }

        public string UserName
        {
            get
            {
                return txtUserName.Text;
            }
            set
            {
                txtUserName.Text = value;
            }
        }

        public string Password
        {
            get
            {
                return txtPassword.Text;
            }
            set
            {
                txtPassword.Text = value;
            }
        }
        #endregion

    }
}